package com.example.alioss.runner;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.thymeleaf.util.StringUtils;
import redis.clients.jedis.Jedis;
import sun.rmi.runtime.Log;

/**
 * spring boot 容器加载后自动监听
 */
@Component
public class MyCommandRunner implements CommandLineRunner {
    @Value("${spring.web.index}")
    private String indexUrl;
    @Value("${spring.redis.host}")
    private String redisHost;
    @Value("${spring.redis.port}")
    private Integer redisPort;
    @Value("${spring.redis.password}")
    private String redisPassword;


    @Override
    public void run(String... args) throws Exception {
        //项目启动后自动打开浏览器的项目启动页面indexUrl
        checkRedisConnect();
        System.out.println("上传页面地址：" + indexUrl);
//        Runtime.getRuntime().exec("cmd /c start " + indexUrl);  // 可以指定自己的路径
    }

    public void checkRedisConnect() {
        Jedis jedis = new Jedis(redisHost, redisPort);
        if (!StringUtils.isEmpty(redisPassword)) jedis.auth(redisPassword);
        String ping = jedis.ping();
        System.out.println("========redis========连接成功" + ping);
    }
}
